package experiment.e02.code;

import java.util.Scanner;

/**
 * @author thinkpad - 83start
 * @version v1.0
 * @create 2022/9/22 15:43
 * @package experiment.e02.code
 * @description 程求s=1!+2!+…+n!（n从键盘输入），采用方法调用的方式实现。
 */

public class E04 {

    public static void main(String[] args) {
        System.out.println("请输入 n :");
        int n = new Scanner(System.in).nextInt();

        int sum1 = accumulate(n);

        System.out.println(sum1);
    }

    public static int accumulate(int n){
        int sum1 = 0;
        // 阶乘累加
        for (int i = 1; i <= n; i++) {
            int sum2 = 1;
            // 计算阶乘
            for (int j = 1; j <= i ; j++) {
                sum2 *= j;
            }
            sum1 += sum2;
        }

        return sum1;
    }
}
